package cc.monggo.web.controller.login;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cc.monggo.common.AbstractBaseController;
import cc.monggo.web.form.LoginForm;
import cc.monggo.web.form.UserForm;

@Controller
public class LoginController extends AbstractBaseController {	
	@RequestMapping(value="login")
	public ModelAndView login(HttpServletRequest request,HttpServletResponse response, LoginForm command) 
			throws Exception {
		String username = command.getUsername();
		String password = command.getPassword();
		System.out.println("username --->" + username);
		
		//BaseUserDAO dao = new BaseUserDAOImpl();
		//List<BaseUser> list = dao.selectAll();
		//System.out.println(list.get(0).getUserName());
		
		//UserForm form = (UserForm)command;
		loginService.insertLoginInfo();
		
		return new ModelAndView("/login/index","message","Hello" + command.getUsername());
	}
	
	@RequestMapping(value="login2.json")
	public ModelAndView login_json(HttpServletRequest request,HttpServletResponse response, UserForm command) throws Exception{
		String username = command.getUsername();
		String password = command.getPassword();
		System.out.println("username --->" + username);
		
		PrintWriter out = response.getWriter();
		out.print("{username:'OK'}");
		//UserForm form = (UserForm)command;
		return null;
	}
	
	@RequestMapping(value="login4pop")
	public ModelAndView login4pop(HttpServletRequest request,HttpServletResponse response, LoginForm command) 
			throws Exception {
		//String username = command.getUsername();
		//String password = command.getPassword();
		//System.out.println("username --->" + username);
		
		//BaseUserDAO dao = new BaseUserDAOImpl();
		//List<BaseUser> list = dao.selectAll();
		//System.out.println(list.get(0).getUserName());
		
		//UserForm form = (UserForm)command;
		//loginService.insertLoginInfo();
		long sum = 0;
		for(long i=0;i<10000000;i++){
			for(int j=0;j<1;j++){
				sum = sum -1;
			}
			sum = sum + i;
			
		}
		
		return new ModelAndView("/exam_popup/pop","message","Hello" + sum);
	}
}
